package com.heima.admin.controller.v1;
import com.heima.admin.service.AdChannelService;
import com.heima.model.admin.dtos.ChannelDTO;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
@Api(value = "频道管理",tags = "频道管理",description = "频道管理API")
public class AdChannelController {
    @Autowired
    private AdChannelService channelService;
    @PostMapping("/list")
    @ApiOperation("频道分页列表查询")
    public ResponseResult findByNameAndPage(@RequestBody ChannelDTO dto) {
        return channelService.findByNameAndPage(dto);
    }

    @PostMapping("/save")
    @ApiOperation("频道新增")
    public ResponseResult insertAdchannel(@RequestBody AdChannel adChannel){
        return channelService.insertAdchannel(adChannel);
    }
    @PostMapping("/update")
    @ApiOperation("频道修改")
    public ResponseResult updateAdchannel(@RequestBody AdChannel adChannel){
        return channelService.updateAdchannel(adChannel);
    }

    @GetMapping("/del/{id}")
    @ApiOperation("频道删除")
    public ResponseResult deleteAdchannel(@PathVariable Integer id){
        return channelService.deleteAdchannel(id);
    }

    @ApiOperation("查询全部")
    @GetMapping("/channels")
    public ResponseResult selectAll(){
        List<AdChannel> list = channelService.list();
        return ResponseResult.okResult(list);
    }
    @ApiOperation("根据id查询频道")
    @GetMapping("/one/{id}")
    public ResponseResult<AdChannel> selectOne(@PathVariable("id") Integer id){
        return ResponseResult.okResult(channelService.getById(id));
    }
}